package com.lindroy.jetpacknotes.base

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.fragment.app.Fragment

/**
 * @author Lin
 * @date 2021/11/9
 * @function
 */
private const val TAG = "TAG"

abstract class BaseFragment(@LayoutRes val layoutId: Int) : Fragment() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setLog("onCreate")
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ):View = inflater.inflate(layoutId, container, false)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        setLog("onViewCreated")
        initView(savedInstanceState)
        initListener()
    }

    override fun onDestroyView() {
        super.onDestroyView()
        setLog("onDestroyView")
    }

    override fun onDestroy() {
        super.onDestroy()
        setLog("onDestroy")
    }

    private fun setLog(lifeStatus: String) {
        Log.d(TAG, "${javaClass.simpleName}--${this.hashCode()}---$lifeStatus")
    }

    abstract fun initView(savedInstanceState: Bundle?)
    abstract fun initListener()

}